# import io
# import subprocess
# from PIL import Image
# import numpy as np
#
#
# def is_black_screen(device_id):
#     # f'adb -s {device_id} exec-out screencap -p'会把截图的二进制输出出来
#     img_bytes = subprocess.check_output(
#         f'adb -s {device_id} exec-out screencap -p',
#         shell=True
#     )
#
#     # 使用Pillow库从字节流中读取图像
#     img = Image.open(io.BytesIO(img_bytes))
#
#     # 转换成numpy数组（像素矩阵）
#     arr = np.array(img)
#
#     # 计算图片像素的平均亮度（数值越低，越接近黑色）
#     brightness = arr.mean()
#
#     print(brightness)
#
#     # 如果brightness小于30，判定为黑屏
#     return brightness < 30
#
#
# if __name__ == '__main__':
#     if is_black_screen("127.0.0.1:21513"):
#         print("检测到黑屏，需要重启app")
